<script type="text/javascript">
//<![CDATA[
	function addMasterCode(){
		with(document.frmMaster){
			submit();
		}
	}

	function initMasterCode(){ //마스터 코드 폼 초기화
		$(".btn_master img").eq(0).attr("src","/theme/<?=$_theme?>/images/common/btn_addition.gif");
		$(".btn_master .btn_cancel").hide();
		$(".btn_master .btn_delete").hide();
		with(document.frmMaster){
			reset();
			dbjob.value = 'i';
			open_yn.value = 'Y';
		}
		slide_open('.frmMaster');
	}

	function initChildCode(){ //차일드 코드 폼 초기화
		$(".btn_child img").eq(0).attr("src","/theme/<?=$_theme?>/images/common/btn_addition.gif");
		$(".btn_child .btn_cancel").hide();
		$(".btn_child .btn_delete").hide();
		with(document.frmChild){
			reset();
			dbjob.value = 'i';
			open_yn.value = 'Y';
		}
		slide_open('.frmChild');
	}

	function addChildCode(){ //차일드 코드 추가
		with(document.frmChild){
			submit();
		}
	}

	function deleteMasterCode(){
		if(!confirm('마스터 코드를 삭제하시겠습니까?\n\n삭제시 관련 하위 코드도 함께 삭제됩니다.\n\n그래도 삭제하시겠습니까?')) return;
		with(document.frmMaster){
			dbjob.value = "d";
			submit();
		}
	}

	function deleteChildCode(){
		if(!confirm('차일드 코드를 삭제하시겠습니까?\n\n삭제시 관련 시스템이 오작동을 일으킬수 있습니다.\n\n그래도 삭제하시겠습니까?')) return;
		with(document.frmChild){
			dbjob.value = "d";
			submit();
		}
	}

	function setOrderBy(no,db){ //코드 순서 조정
		with(document.frmChild){
			code_id.value = no;
			dbjob.value = db;
			submit();
		}
	}

	function getMasterCodeList(){ //마스트 코드 리스트
		$.ajax({
			type: "GET",
			url: "/setting/ajax_master_code",
			/*data: "sch_term="+term,*/
			success: function(data){
				$("#master-code").html(data);

				$(".master_link").click(function(){
					var id = $(this).attr("master_id");
					
					$.ajax({
						type: "GET",
						url: "/setting/ajax_master_select",
						data: "master_id="+id,
						success: function(data){
							var rst = eval('('+data+')');
							with(document.frmMaster){
								dbjob.value = 'u';
								master_id.value = rst.master_id;
								title.value = rst.title;
								open_yn.value = rst.open_yn;
								etc1.value =  rst.etc1;
								etc2.value =  rst.etc2;
								etc3.value =  rst.etc3;
							}
							slide_open('.frmMaster');
							$(".btn_master img").eq(0).attr("src","/theme/<?=$_theme?>/images/common/btn_modify.gif");
							$(".btn_master img").show();

							//Child Code
							
							getChildCodeList(rst.master_id);
							
						},
						error:function(error){alert('에러1');}
					});
				});
			},
			error:function(error){alert('에러2');}
		});
	}

	function getChildCodeList(id){
		var str_id = id;
		if(!str_id)return;
		$(".btn_child .btn_add").show();
		
		with(document.frmChild){
			master_id.value = str_id;
		}
		
		$.ajax({
			type: "GET",
			url: "/setting/ajax_child_code",
			data: "master_id="+str_id,
			success: function(data){
				$("#child-code").html(data);

				$(".child_link").click(function(){
					var code_id = $(this).attr("code_id");
					
					$.ajax({
						type: "GET",
						url: "/setting/ajax_child_select",
						data: "code_id="+code_id,
						success: function(data){
							var rst = eval('('+data+')');
							with(document.frmChild){
								dbjob.value = 'u';
								code_id.value = rst.code_id;
								title.value = rst.title;
								open_yn.value = rst.open_yn;
								etc1.value =  rst.etc1;
								etc2.value =  rst.etc2;
								etc3.value =  rst.etc3;
							}
							slide_open('.frmChild');
							$(".btn_child img").eq(0).attr("src","/theme/<?=$_theme?>/images/common/btn_modify.gif");
							$(".btn_child img").show();

							//Child Code
							$(".btn_child_add").show();
							
							with(document.frmChild){
								master_id.value = rst.master_id;
							}
						},
						error:function(error){alert('에러');}
					});
				});
			},
			error:function(error){alert('에러');}
		});
	}

	$(function(){
		getMasterCodeList();
		with(document.frmChild){
			getChildCodeList(master_id.value);
		}
		
	});	
//]]>
</script>
<style type="text/css">
	.master_link, .child_link{cursor:pointer;}
	.open_n td{text-decoration:line-through;background:#999 !important;}
	.btn_master a{margin-right:5px}
	.btn_master .btn_cancel ,btn_master .btn_delete{display:none}
	.btn_child a{margin-right:5px}
	.btn_child .btn_add,.btn_child .btn_cancel,.btn_child .btn_delete{display:none}
</style>
<div class="box_type02">
	<h2 class="txt">코드관리</h2>
	<p class="icon"><a href="javascript:void(0);" class="icon_m04">매뉴얼</a></p>

	<div class="codeCont">
		<ul class="c_box">
			<li class="left">
			<!--[s] 쓰기 -->
			<form  name="frmMaster" class="frmMaster" method="post"  action="/setting/codeMasterDbjob">
			<input type="hidden" name="dbjob" value="i">
			<input type="hidden" name="master_id" value="">
				<fieldset class="board_write">
					<legend>코드관리</legend>
					<table cellspacing="0" summary="코드관리" class="lines">
						<caption>코드관리</caption>
						<!--<tr>
							<th scope="row" width="128"><p class="point">그룹코드</p></th>
							<td>
								<div><input type="text" id="" name="" class="ip_i" style="width:203px;" value="" /></div>
							</td>
						</tr> -->
						<tr>
							<th scope="row"><p class="point">그룹명</p></th>
							<td>
								<div><input type="text" id="" name="title" class="ip_i" style="width:203px;" value="" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">사용여부</p></th>
							<td>
								<div>
									<a href="javascript:void(0);" class="disBtn masterDisBtn"><img src="/theme/<?=$_theme?>/images/common/btn_on_off.gif" alt="on" /></a>
									<!-- 히든 인풋박스에 on off 들어가게 구성되어 있음 -->
									<input type="hidden" id="displays" name="open_yn" value="Y" />
								</div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">비고1</p></th>
							<td>
								<div><input type="text" id="" name="etc1" class="ip_i" style="width:203px;" value="" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">비고2</p></th>
							<td>
								<div><input type="text" id="" name="etc2" class="ip_i" style="width:203px;" value="" /></div>
							</td>
						</tr>
						<tr>
							<th scope="row"><p class="point">비고3</p></th>
							<td>
								<div><input type="text" id="" name="etc3" class="ip_i" style="width:203px;" value="" /></div>
							</td>
						</tr>
					</table>
				</fieldset>
			</form>
			<!--[e] 쓰기 -->

			<div class="search_type01 btn_master">
				<a href="javascript:addMasterCode()"><img src="/theme/<?=$_theme?>/images/common/btn_addition.gif" alt="추가" /></a>
				<a href="javascript:initMasterCode()"><img src="/theme/<?=$_theme?>/images/common/btn_cancel.gif" alt="취소" class="btn_cancel" /></a>
				<a href="javascript:deleteMasterCode()"><img src="/theme/<?=$_theme?>/images/common/btn_delete.gif" alt="삭제" class="btn_delete" /></a>
			</div>

			<!--[s] 목록 -->
			<div id="master-code" class="codeScroll"></div>
			<!--[e] 목록 -->
		</li>
			<li class="right">
				<!--[s] 쓰기 -->
				<form name="frmChild" class="frmChild" method="post" action="/setting/codeChildDbjob">
				<input type="hidden" name="dbjob" value="i">
				<input type="hidden" name="code_id" value="">
				<input type="hidden" name="master_id" value="<?php echo $master_id?>">
					<fieldset class="board_write">
						<legend>코드관리</legend>
						<table cellspacing="0" summary="코드관리" class="lines">
							<caption>코드관리</caption>
							<tr>
								<th scope="row"><p class="point">코드명</p></th>
								<td>
									<div><input type="text" id="" name="title" class="ip_i" style="width:203px;" value="" /></div>
								</td>
							</tr>
							<tr>
								<th scope="row"><p class="point">사용여부</p></th>
								<td>
									<div>
										<a href="javascript:void(0);" class="disBtn  childDisBtn"><img src="/theme/<?=$_theme?>/images/common/btn_on_off.gif" alt="on" /></a>
										<!-- 히든 인풋박스에 on off 들어가게 구성되어 있음 -->
										<input type="hidden" id="displays" name="open_yn" value="Y" />
									</div>
								</td>
							</tr>
							<tr>
								<th scope="row"><p class="point">비고1</p></th>
								<td>
									<div><input type="text" id="" name="etc1" class="ip_i" style="width:203px;" value="" /></div>
								</td>
							</tr>
							<tr>
								<th scope="row"><p class="point">비고2</p></th>
								<td>
									<div><input type="text" id="" name="etc2" class="ip_i" style="width:203px;" value="" /></div>
								</td>
							</tr>
							<tr>
								<th scope="row"><p class="point">비고3</p></th>
								<td>
									<div><input type="text" id="" name="etc3" class="ip_i" style="width:203px;" value="" /></div>
								</td>
							</tr>
						</table>
					</fieldset>
				</form>
				<!--[e] 쓰기 -->
	
				<div class="search_type01 btn_child">
					<a href="javascript:addChildCode()"><img src="/theme/<?=$_theme?>/images/common/btn_addition.gif" alt="추가" class="btn_add" /></a>
					<a href="javascript:initChildCode()"><img src="/theme/<?=$_theme?>/images/common/btn_cancel.gif" alt="취소" class="btn_cancel" /></a>
					<a href="javascript:deleteChildCode()"><img src="/theme/<?=$_theme?>/images/common/btn_delete.gif" alt="삭제" class="btn_delete" /></a>
				</div>
	
				<!--[s] 목록 -->
				<div id="child-code" class="codeScroll"></div>
					
				</div>
				<!--[e] 목록 -->
			</li>
		</ul>
	</div>

	<!--[s] Tip -->
	<dl id="tip">
		<dt>Tip</dt>
		<dd>인터넷익스플로러의 '호환성보기' 기능을 사용중인 접속자에게 자동으로 최신버전 기준으로 사이트를 출력하도록 처리합니다.</dd>
		<dd>코딩방식에 따라 특정 버전의 브라우저에서 사이트가 깨질수 있으니, 충분한 테스트 후 기능을 설정해 주시기 바랍니다.</dd>
	</dl>
	<!--[e] Tip -->
</div>